package com.getword.service.impl;


import com.getword.domain.City;
import com.getword.mongodao.CityRepository;
import com.getword.service.CityService;
import com.getword.web.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CityServiceImpl implements CityService {
    @Autowired
    private CityRepository cityRepository;

    @Override
    public Result getCities(Integer level, Integer parentId) {
        List<City> cities = cityRepository.findCitiesByLevelAndParentIdOrderByFirst(level, parentId);
        return Result.success(cities);
    }

    @Override
    public Result getCitiesByArea(Integer areaId) {
        City city = cityRepository.findCityById(areaId);
        if(city!=null)
            return Result.success(city.getParentId());
        return Result.fail("城市不存在");
    }

    @Override
    public Result getById(Integer id) {
        return Result.success(cityRepository.findCityById(id));
    }
}
